import {Dialog} from "vant";
import { $import } from '@/api/import'
import { $export } from "@/api/export"
export const addTransport = {
  data() {
    return {
      phone: ''
    }
  },
  methods: {
    // 编辑
    handleEdit(item) {
      this.editItem = item
      this.title = '编辑航段'
      if (this.phone === 'ios') {
        sessionStorage.setItem('record', JSON.stringify(this.exportObj))
        sessionStorage.setItem('exportObj', JSON.stringify(this.exportObj))
        sessionStorage.setItem('item', JSON.stringify(this.editItem))
        this.$router.push({
          path: '/addTransport',
          query: {
            type: '新增航段'
          }
        })
      }
      else {
        this.isShow = true
      }
    },
    // 删除
    handleCancle(item) {
      const obj = {
        fid: item.fid,
        purchaser: this.importObj.purchaser
      }
      let _this = this
      Dialog.confirm({
        title: '删除航段',
        message: '确认删除该航段?',
        beforeClose(action, done) {
          if (action === 'confirm') {
            $import.remove(obj)
                   .then(res => {
                     if (res.status === 200) {
                        _this.$msg.success(res.msg || res.message || '操作成功')
                        _this.handleDetail(_this.record)
                      }
                      else {
                        _this.$msg.fail(res.msg || res.message || '网络错误,请稍后再试')
                      }
                   })
                   .catch(err => _this.$msg.fail(err.msg || err.message || '网络错误,请稍后再试'))
            done()
          } else {
            done()
          }
        }
      })
    },
    // 新增航段
    handleAdd() {
      this.title = '新增航段'
      if (this.phone === 'ios') {
        sessionStorage.setItem('record', JSON.stringify(this.importObj))
        sessionStorage.setItem('exportObj', JSON.stringify(this.importObj))
        sessionStorage.setItem('item', JSON.stringify(this.editItem))
        this.$router.push({
          path: '/addTransport',
          query: {
            type: '新增航段'
          }
        })
      }
      else {
        this.isShow = true
      }
    },
  }
}

export const eAddTransport = {
  data() {
    return {
      phone: ''
    }
  },
  methods: {
    // 编辑
    handleEdit(item) {
      this.editItem = item
      this.title = '编辑航段'
      if (this.phone === 'ios') {
        sessionStorage.setItem('record', JSON.stringify(this.exportObj))
        sessionStorage.setItem('exportObj', JSON.stringify(this.exportObj))
        sessionStorage.setItem('item', JSON.stringify(this.editItem))
        this.$router.push({
          path: '/addTransport',
          query: {
            type: '新增航段'
          }
        })
      }
      else {
        this.isShow = true
      }
    },
    // 删除
    handleCancle(item) {
      const obj = {
        fid: item.fid,
        purchaser: this.exportObj.purchaser
      }
      let _this = this
      Dialog.confirm({
        title: '删除航段',
        message: '确认删除该航段?',
        beforeClose(action, done) {
          if (action === 'confirm') {
            $export.remove(obj)
                   .then(res => {
                     if (res.status === 200) {
                        _this.$msg.success(res.msg || res.message || '操作成功')
                        _this.handleDetail(_this.number)
                      }
                      else {
                        _this.$msg.fail(res.msg || res.message || '网络错误,请稍后再试')
                      }
                   })
                   .catch(err => _this.$msg.fail(err.message || '网络错误,请稍后再试'))
            done()
          } else {
            done()
          }
        }
      })
    },
    // 新增航段
    handleAdd() {
      this.title = '新增航段'
      if (this.phone === 'ios') {
        sessionStorage.setItem('record', JSON.stringify(this.exportObj))
        sessionStorage.setItem('exportObj', JSON.stringify(this.exportObj))
        sessionStorage.setItem('item', JSON.stringify(this.editItem))
        this.$router.push({
          path: '/addTransport',
          query: {
            type: '新增航段'
          }
        })
      }
      else {
        this.isShow = true
      }
    },
  }
}
